/*
 * @lc app=leetcode.cn id=888 lang=typescript
 *
 * [888] 公平的糖果交换
 */

// @lc code=start
function fairCandySwap(aliceSizes: number[], bobSizes: number[]): number[] {
    // 1. 求交换的两个个数的差值
    const a_sum = aliceSizes.reduce((a, b) => a + b, 0);
    const b_sum = bobSizes.reduce((a, b) => a + b, 0);
    const diff = (a_sum - b_sum) / 2;

    // 2. 找目标差值
    for (let i = 0; i < aliceSizes.length; i++) {
        const element = aliceSizes[i];
        if (bobSizes.includes(element - diff)) {
            return [element, element - diff];
        }
    }
    return [];
}
// @lc code=end
